package online.heycm.rbac.common.utils;

/**
 * @author hey
 * @version 1.0
 * @date 2024/1/19 17:34
 */
public class NicknameUtil {

    private static final String NICKNAME_FORMAT = "用户%s";

    private static final int DIGIT = 6;

    private NicknameUtil() {
    }

    public static String generate() {
        return String.format(NICKNAME_FORMAT, generateRandomDigitsString(DIGIT));
    }

    private static String generateRandomDigitsString(int digit) {
        return String.format("%0" + digit + "d", generateRandomDigits(digit));
    }

    private static int generateRandomDigits(int digit) {
        // 计算最大可能的该位数整数
        int maxForDigits = (int) Math.pow(10, digit) - 1;
        // 生成指定范围内的随机数
        return (int) (Math.random() * (maxForDigits + 1));
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            System.out.println(generate());
        }
    }
}
